<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">

<ui:include src="/WEB-INF/includes/head.xhtml">
	<ui:param name="pageTitle" value="Edit stations" />
</ui:include>
<h:body>
	<ui:include src="/WEB-INF/includes/menu.xhtml" />
	<h1>Edit stations</h1>
	
	<h:form id="form1">

		<!-- Error messages -->
		<p:messages id="messages" closable="true" autoUpdate="true" />

		<p:panelGrid styleClass="noBorders">
			<p:row>
				<p:column>
					<h:outputLabel for="stationName" value="Station" />
				</p:column>
				<p:column>
					<p:inputText id="stationName" value="#{editStations.newStation}"
						required="true"
						requiredMessage="Please insert name of new station" />
				</p:column>
				<p:column>
					<p:commandButton value="Add">
						<f:ajax listener="#{editStations.add}" execute="stationName"
							update=":form2:stationsTable" render=":form2:stationsTable" />
					</p:commandButton>
				</p:column>
			</p:row>
			<p:row>
				<p:column>
					<p:spacer height="50" />
				</p:column>
			</p:row>
		</p:panelGrid>

	</h:form>
	
	<h:form id="form2">
		<p:contextMenu for="stationsTable">
			<p:menuitem value="Delete" update="stationsTable" render="stationsTable" icon="ui-icon-close" actionListener="#{editStations.delete}" />
		</p:contextMenu>

		<!-- Schedule table -->
		<p:dataTable id="stationsTable" var="station"
			value="#{editStations.stations}" rowKey="#{station}"
			selection="#{editStations.stationToDelete}" selectionMode="single"
			paginator="true" rows="10" paginatorPosition="bottom">
			<p:column headerText="Station name">
				<h:outputText value="#{station}" />
			</p:column>
		</p:dataTable>
	</h:form>

</h:body>
</html>